package com.mysoft.gfyx.common.rpc.mpapi.impl;

import com.mysoft.gfyx.common.rpc.mpapi.MpapiClientFactoryService;
import com.mysoft.gfyx.common.rpc.mpapi.MpapiClientService;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class MpapiClientFactoryServiceImpl implements MpapiClientFactoryService {
    @Value("${mpapi.host}")
    private String host;

    @Value("${mpapi.token}")
    private String token;


    @Override
    public MpapiClientService getMpapiClientService() {
        MpapiClientService service = Feign.builder()
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .requestInterceptor((new MpapiRequestInterceptorImpl(token)))
                .target(MpapiClientService.class, host);

        return service;
    }
}
